package com.motorhome.manage.controller;

import com.motorhome.base.dao.Pager;
import com.motorhome.base.easyui.EasyuiDataGridResult;
import com.motorhome.base.util.Result;
import com.motorhome.manage.domain.Order;
import com.motorhome.manage.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: John
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/index")
    public String index(HttpServletRequest request) {
        return "order/index";
    }

    @RequestMapping(value = "/getOrderList", method = RequestMethod.POST)
    public @ResponseBody String getOrderList(HttpServletRequest request) {
        String page = request.getParameter("page");
        String rows = request.getParameter("rows");
        Pager<Order> pager = orderService.getOrderList(page, rows);
        return new EasyuiDataGridResult<>(pager.getTotalCount(), pager.getItems()).toJson();
    }

    @RequestMapping(value = "/updateOrderStatus", method = RequestMethod.POST)
    public @ResponseBody Result updateOrderStatus(HttpServletRequest request) {
        String id = request.getParameter("id");
        String status = request.getParameter("status");
        return orderService.updateOrderStatus(id, status);
    }

    @RequestMapping(value = "/deleteOrder", method = RequestMethod.POST)
    public @ResponseBody Result deleteOrder(HttpServletRequest request) {
        String id = request.getParameter("id");
        return orderService.deleteOrder(id);
    }

    @RequestMapping(value = "/updateMemberPoint", method = RequestMethod.POST)
    public @ResponseBody Result updateMemberPoint(HttpServletRequest request) {
        String id = request.getParameter("id");
        return orderService.updateMemberPoint(id);
    }

}
